package org.test4j.mock.faking.fluent;

import org.test4j.mock.faking.meta.TimesVerify;

/**
 * 自定义mock行为
 *
 * @author darui.wu
 */
public class MockMethodWithTimes<R> extends MockMethod<R> {
    private final String classMethod;

    public MockMethodWithTimes(FluentMockUp mockUp, String realClass, String name, String desc) {
        super(mockUp, realClass, name, desc);
        this.classMethod = realClass + "#" + name + desc;
    }

    /**
     * 调用次数不少于times次
     *
     * @param times
     * @return
     */
    public MockMethod<R> min(int times) {
        TimesVerify.min(this.classMethod, times);
        super.mockUp.apply();
        return this;
    }

    /**
     * 调用次数不超过times次
     *
     * @param times
     * @return
     */
    public MockMethod<R> max(int times) {
        TimesVerify.max(this.classMethod, times);
        super.mockUp.apply();
        return this;
    }

    /**
     * 方法应该不被调用
     */
    public void never() {
        TimesVerify.never(this.classMethod);
        super.mockUp.apply();
    }

    /**
     * 调用次数在 [min, max]之间
     *
     * @param min
     * @param max
     * @return
     */
    public MockMethod<R> between(int min, int max) {
        TimesVerify.between(this.classMethod, min, max);
        super.mockUp.apply();
        return this;
    }

    /**
     * 恰好调用times次
     *
     * @param times
     * @return
     */
    public MockMethod<R> just(int times) {
        TimesVerify.just(this.classMethod, times);
        super.mockUp.apply();
        return this;
    }
}